'\" te
.\" Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH CPUID 4D "April 9, 2016"
.SH NAME
cpuid \- CPU identification driver
.SH SYNOPSIS
.LP
.nf
\fB/dev/cpu/self/cpuid\fR
.fi

.SH DESCRIPTION
.SS "SPARC and x86 system"
.LP
This device provides implementation-private information via ioctls about
various aspects of the implementation to Solaris libraries and utilities.
.SS "x86 systems only"
.LP
This device also provides a file-like view of the namespace and return values
of the x86 cpuid instruction. The cpuid instruction takes a single 32-bit
integer function code, and returns four 32-bit integer values corresponding to
the input value that describe various aspects of the capabilities and
configuration of the processor.
.LP
The API for the character device consists of using the seek offset to set the
function code value, and using a \fBread\fR(2) or \fBpread\fR(2) of 16 bytes to
fetch the four 32-bit return values of the instruction in the order %\fBeax\fR,
%\fBebx\fR, %\fBecx\fR and %\fBedx\fR.
.LP
No data can be written to the device. Like the \fBcpuid\fR instruction, no
special privileges are required to use the device.
.LP
The device is useful to enable low-level configuration information to be
extracted from the CPU without having to write any assembler code to invoke the
\fBcpuid\fR instruction directly. It also allows the kernel to attempt to
correct any erroneous data returned by the instruction (prompted by occasional
errors in the information exported by various processor implementations over
the years).
.LP
See the processor manufacturers documentation for further information about the
syntax and semantics of the wide variety of information available from this
instruction.
.SH EXAMPLE
.LP
This example allows you to determine if the current x86 processor supports
"long mode," which is a necessary (but not sufficient) condition for running
the 64-bit Solaris kernel on the processor.
.sp
.in +2
.nf
/*

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>

static const char devname[] = "/dev/cpu/self/cpuid";

/*ARGSUSED*/
int
main(int argc, char *argv[])
{
        struct {
                uint32_t r_eax, r_ebx, r_ecx, r_edx;
        } _r, *rp = &_r;
        int d;
        char *s;

        if ((d = open(devname, O_RDONLY)) == -1) {
                perror(devname);
                return (1);
        }

        if (pread(d, rp, sizeof (*rp), 0) != sizeof (*rp)) {
                perror(devname);
                goto fail;
        }

        s = (char *)&rp->r_ebx;
        if (strncmp(s, "Auth" "cAMD" "enti", 12) != 0 &&
            strncmp(s, "Genu" "ntel" "ineI", 12) != 0)
                goto fail;

        if (pread(d, rp, sizeof (*rp), 0x80000001) == sizeof (*rp)) {
                /*
                 * Read extended feature word; check bit 29
                 */
                (void) close(d);
                if ((rp->r_edx >> 29) & 1) {
                        (void) printf("processor supports long mode\en");
                        return (0);
                }
        }
fail:
        (void) close(d);
        return (1);
}
.fi
.in -2

.SH ERRORS
.ne 2
.na
\fBENXIO\fR
.ad
.RS 10n
Results from attempting to read data from the device on a system that does not
support the CPU identification interfaces
.RE

.sp
.ne 2
.na
\fBEINVAL\fR
.ad
.RS 10n
Results from reading from an offset larger than UINT_MAX, or attempting to read
with a size that is not multiple of 16 bytes.
.RE

.SH FILES
.ne 2
.na
\fB\fB/dev/cpu/self/cpuid\fR\fR
.ad
.RS 23n
Provides access to CPU identification data.
.RE

.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Evolving
.TE

.SH SEE ALSO
.LP
.BR pread (2),
.BR read (2),
.BR attributes (7),
.BR prtconf (8),
.BR psrinfo (8)
